﻿Imports MICROFORMA.BEL
Imports MICROFORMA.BLL


Public Class frmSolicitud
    Dim _SolicitudBL As SolicitudBL
    Dim _SolicitudBE As SolicitudBE



    Sub New()
        _SolicitudBL = New SolicitudBL
        InitializeComponent()
    End Sub


    Private Sub lnkNewIndice_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkNewIndice.LinkClicked
        Dim _frmAddSolicitud As New frmAddSolicitud
        _frmAddSolicitud.ShowDialog()
        Call LoadList()
        _frmAddSolicitud.Dispose()
    End Sub

    Private Sub lnkUpdateIndice_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkUpdateIndice.LinkClicked
        If lstvIndices.SelectedItems.Count > 0 Then
            Call ShowFormListAdd(True, CShort(lstvIndices.SelectedItems(0).Text.Trim))
        End If
        Call LoadList()
    End Sub

    Private Sub lnkPermisos_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkPermisos.LinkClicked
        If lstvIndices.SelectedItems.Count > 0 Then
            Call DeleteDataExternal(lstvIndices.SelectedItems(0).Text)
            Call LoadList()
        Else
            MessageMistake("Por favor Seleccione un Registro.")
            lstvIndices.Focus()
        End If
    End Sub

    Private Sub frmSolicitud_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        LoadList()
    End Sub

    Private Sub LoadList()
        lstvIndices.Items.Clear()

        Dim _datableIndices As DataTable = _SolicitudBL.GetList
        Dim lviItem As ListViewItem

        For Each dtrFila As DataRow In _datableIndices.Rows
            lviItem = New ListViewItem
            lviItem.Text = dtrFila("IdSolicitud")
            lviItem.SubItems.Add(dtrFila("Cliente"))
            lviItem.SubItems.Add(dtrFila("Fecha"))
            lviItem.SubItems.Add(dtrFila("IdTipo"))
            lstvIndices.Items.Add(lviItem)
        Next

    End Sub


    Private Sub ShowFormListAdd(Optional ByVal bolUpdate As Boolean = Nothing, Optional ByVal idIndice As Short = 0)

        Dim _frmAddSolicitud As New frmAddSolicitud
        _frmAddSolicitud.bolUpdate = bolUpdate
        _frmAddSolicitud.pIdSolicitud = CShort(lstvIndices.SelectedItems(0).Text.Trim)
        
        _frmAddSolicitud.ShowDialog()
        _frmAddSolicitud.Dispose()

    End Sub

    Private Sub lstvIndices_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstvIndices.DoubleClick
        If lstvIndices.SelectedItems.Count > 0 Then
            Call ShowFormListAdd(True, CShort(lstvIndices.SelectedItems(0).Text.Trim))
        End If

    End Sub

    Private Sub DeleteDataExternal(ByVal Id As Integer)
        If MessageMakeAction("Esta Seguro de eliminar el Registro Seleccionado.") Then
            
            Dim msg As String = _SolicitudBL.Delete(Id)
            If Not msg = "OK" Then
                MessageMistake(msg)
            End If
        End If
    End Sub


    Private Sub lstvIndices_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstvIndices.SelectedIndexChanged

    End Sub
End Class